<?php
load_info_var($cf_controller);	   //加载smarty变量
load_file('goods_class', LIB_PATH);
$main = new Goods($db);
$id = isset($_POST['id']) ? intval($_POST['id']) : intval($_GET['id']);
$return_page = $cf_pre_page ? $cf_pre_page : $cf_self_page;

switch ($cf_action) {
    case "index":
	$article_cate = add_array_item(array('' => '全部'), $article_cate);
	$smarty->mypage($cf_controller, $cf_action, 0);	
	$skey = isset($_POST['skey']) ? trim($_POST['skey']) : urldecode($_GET['skey']);
	$skey2 = isset($_POST['skey2']) ? trim($_POST['skey2']) : urldecode($_GET['skey2']);
	$skey3 = isset($_POST['skey3']) ? trim($_POST['skey3']) : urldecode($_GET['skey3']);
	$skey4 = isset($_POST['skey4']) ? trim($_POST['skey4']) : urldecode($_GET['skey4']);
	$self = isset($_POST['self']) ? trim($_POST['self']) : urldecode($_GET['self']);	
	$where = '1';
	if (is_numeric($self)) {
	    $where .= " and comment_status = '" . $self . "'";
	}
	
	if ($skey) {
	    $where .= " and comment_content like '%" . $skey . "%'";
	}	
	if ($skey2 && $skey3) {
            $where .= " AND DATE_FORMAT(comment_create_time,'%Y-%m-%d')  BETWEEN '".$skey2."' AND '".$skey3."'";
    }
	if ($skey4) {
	   $where .= " and comment_nickname like '%" . $skey4 . "%'";
	}
	
	load_file('page_class', LIB_PATH);
	$MyPage = new Mypage($db);
	$field = '*';
	$data_ary = $MyPage->from_sql($field, $main->get_table_name3(), $where, "comment_id DESC", intval($_GET['cpage']), "20");
	$page = $MyPage->get_page($data, $cf_self_page . '?dpt=' . $cf_dpt . '&skey=' . $skey . '&skey2=' . $skey2 . '&skey3=' . $skey3. '&skey4=' . $skey4);
	

	break;
  
    case "edit":
	if ($cf_ispost) {
		$id = intval($_POST['id']);
	    $data['comment_status'] = trim($_POST['comment_status']);								
	    $result = $main->update_comment($data, "comment_id='".$id."'");		
	    if ($result) {									
			$return_page = $_SESSION['pre_url'] ? $_SESSION['pre_url'] : $cf_self_page;
			unset($_SESSION['pre_url']);
		    my_success('修改成功', '', $return_page, 3);
	    } else {
		    my_error('修改失败');
	    }
	} else {		
	    $smarty->mypage($cf_controller, $cf_action, 0);
	    $_SESSION['pre_url'] = $cf_pre_page ? $cf_pre_page : '';
		$row = $main->get_comment_row($id);
		if($row['comment_images']){
			$row['comment_images'] = explode(',',$row['comment_images']);			
		}
		//dump($row);		
	    if (!$row)
		my_jump('沒有此信息');
	
		
		
		
		//dump($row);
	    //my_print($row['item']);
	   
	}
	break;
  case "del":		
		$result = $main->del_goods_comment($id);
		if ($result) {
				my_success('删除成功', '', $return_page, 1);
		} else {
				my_error('删除失败!');
		}
	break;
	case "detail":
	$smarty->mypage($cf_controller, $cf_action, 0);
	$row = $main->get_data_row($id);
	if (!$row)
	my_jump('沒有此信息');
	
	$row['brand_content'] = htmlspecialchars_decode($row['brand_content']);
	break;  
	default:
	my_jump('非法操作!');
	break;
}


$smarty->assign(array(
    'id' => $id,
    'row' => $row,
    'data_ary' => $data_ary,	
    'page' => $page,   
    'skey' => $skey,
    'skey2' => $skey2,
    'skey3' => $skey3,
	'skey4' => $skey4,
	'self' => $self,
));

$smarty->mydisplay();
?>